package com.example.administrator.xjscc;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.telephony.PhoneNumberUtils;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/12/23.
 */

public class RescueActivity extends Activity {
    private ListView lv_rescue;
    private List<Map<String,Object>> lst_work=new ArrayList<Map<String,Object>>();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_rescue);

        lv_rescue=(ListView)findViewById(R.id.lv_rescue);

        for(int i=0;i<5;i++)
        {
            HashMap<String,Object> map=new HashMap<>();
            map.put("workname","work"+i);
            map.put("phone","123456"+i);
            lst_work.add(map);
        }

        SimpleAdapter ada=new SimpleAdapter(this,lst_work,R.layout.rescueitem,
                new String[]{"workname","phone"},
                new int[]{R.id.tv_workname,R.id.tv_phone});
        lv_rescue.setAdapter(ada);

        lv_rescue.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

                TextView tv=(TextView)view.findViewById(R.id.tv_phone);
                String phone=tv.getText().toString();
                if(PhoneNumberUtils.isGlobalPhoneNumber(phone))
                {
                    Uri phoneUri=Uri.parse("tel:"+phone);
                    Intent tmpi=new Intent(Intent.ACTION_CALL,phoneUri);
                    startActivity(tmpi);
                }
            }
        });
    }
}
